package com.ray.tool.common.enums;

import java.util.stream.Stream;

/**
 * 日志级别 - 枚举类
 *
 * @author LiaoYuXing-Ray
 * @version 1.0
 * @createDate 2023/9/15 16:25
 **/
public enum RayLogLevelEnum {
    INFO(1,"INFO"),
    DEBUG(2,"DEBUG"),
    WARN(3,"WARN"),
    ERROR(4,"ERROR"),
    ;

    /**
     * 索引
     */
    private final Integer index;
    /**
     * 描述
     */
    private final String desc;

    RayLogLevelEnum(Integer index,String desc){
        this.index = index;
        this.desc = desc;
    }

    public Integer getIndex() {
        return index;
    }

    public String getDesc() {
        return desc;
    }

    /**
     * 通过索引获取描述
     *
     * @param index {@link RayLogLevelEnum#index}
     * @return java.lang.String {@link RayLogLevelEnum#desc}
     * @author LiaoYuXing-Ray 2023/11/7 20:22
     **/
    public static String getDescByIndex(Integer index){
        return Stream.of(RayLogLevelEnum.values())
                .filter(enums -> enums.getIndex().equals(index))
                .findFirst()
                .map(RayLogLevelEnum::getDesc)
                .orElse(null);
    }
}
